<template>
  <div>
    <van-icon
      :color="value === 1 ? 'orange' : '#777'"
      :name="value === 1 ? 'good-job' : 'good-job-o'"
      @click="likeFn"
    />
  </div>
</template>

<script>
import { likeArticle, deletelikeArticle } from "@/api/article";
export default {
  props: ["value", "article_id"],
  methods: {
    async likeFn() {
      try {
        let re = 1; //假设点赞
        if (this.value === -1) {
          // 点赞
          await likeArticle(this.article_id);
          this.$toast("已点赞");
        } else {
          //取消点赞
          await deletelikeArticle(this.article_id);
          re = -1;
          this.$toast("已取消");
        }
        this.$emit("input", re);
      } catch (error) {
        console.log(error);
        if (error.response && error.response.status === 401) {
          this.$toast("请先登录");
        }
      }
    },
  },
};
</script>

<style>
</style>